/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PropertiesPanel.java
 *
 * Created on 4/Dez/2011, 17:41:46
 */

package intopo.evogame.partnerselection.tools.config;

import intopo.evogame.partnerselection.chromosome.Chromosome;
import intopo.util.Util;

/**
 * The component that presents the parameters used by all instances of class {@code Chromosome}
 *
 * @author <a href="mailto:mariano.pedro@gmail.com">Pedro Mariano</a>
 *
 * @version 1.0 4/Dez/2011
 *
 * @see intopo.evogame.partnerselection.chromosome.Chromosome.Parameters
 */
public class ChromosomeParametersPanel
	extends javax.swing.JPanel
{

	/** Creates new form PropertiesPanel */
	public ChromosomeParametersPanel ()
	{
		initComponents();
	}
	/**
	 * Update the components after a configuration file has been read.
	 */
	void updateComponents ()
	{
		this.defaultGenesCheckBox.setSelected (Chromosome.Parameters.defaultGenes);
		this.mutationProbabilityFormattedTextField.setValue (new Float (Chromosome.Parameters.mutationProbability));
		this.maxPoolSizeFormattedTextField.setValue (new Integer (Chromosome.Parameters.maxPoolSize));
		this.stddevBitsPerProbabilityFormattedTextField.setValue (new Float (Chromosome.Parameters.stddevBitsPerProbability));
		this.stddevNormalDeltaFormattedTextField.setValue (new Float (Chromosome.Parameters.stddevNormalDelta));
		this.stddevNormalPoolSizeFormattedTextField.setValue (new Float (Chromosome.Parameters.stddevNormalPoolSize));
		this.stddevNormalUtilityThresholdFormattedTextField.setValue (new Float (Chromosome.Parameters.stddevNormalUtilityThreshold));
	}

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
   // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
   private void initComponents() {
      java.awt.GridBagConstraints gridBagConstraints;

      defaultGenesCheckBox = new javax.swing.JCheckBox();
      javax.swing.JLabel jLabel1 = new javax.swing.JLabel();
      mutationProbabilityFormattedTextField = new javax.swing.JFormattedTextField();
      javax.swing.JLabel jLabel2 = new javax.swing.JLabel();
      maxPoolSizeFormattedTextField = new javax.swing.JFormattedTextField();
      javax.swing.JPanel jPanel1 = new javax.swing.JPanel();
      javax.swing.JLabel jLabel3 = new javax.swing.JLabel();
      stddevNormalPoolSizeFormattedTextField = new javax.swing.JFormattedTextField();
      javax.swing.JLabel jLabel4 = new javax.swing.JLabel();
      stddevNormalUtilityThresholdFormattedTextField = new javax.swing.JFormattedTextField();
      javax.swing.JLabel jLabel5 = new javax.swing.JLabel();
      stddevNormalDeltaFormattedTextField = new javax.swing.JFormattedTextField();
      javax.swing.JLabel jLabel6 = new javax.swing.JLabel();
      stddevBitsPerProbabilityFormattedTextField = new javax.swing.JFormattedTextField();

      setBorder(javax.swing.BorderFactory.createTitledBorder("chromosome"));
      setLayout(new java.awt.GridBagLayout());

      defaultGenesCheckBox.setSelected(Chromosome.Parameters.defaultGenes);
      defaultGenesCheckBox.setText("default genes");
      defaultGenesCheckBox.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            defaultGenesCheckBoxActionPerformed(evt);
         }
      });
      gridBagConstraints = new java.awt.GridBagConstraints();
      gridBagConstraints.gridwidth = 2;
      add(defaultGenesCheckBox, gridBagConstraints);

      jLabel1.setText("mutation probability: ");
      gridBagConstraints = new java.awt.GridBagConstraints();
      gridBagConstraints.gridx = 0;
      gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
      add(jLabel1, gridBagConstraints);

      mutationProbabilityFormattedTextField.setColumns(5);
      mutationProbabilityFormattedTextField.setValue(new Float (Chromosome.Parameters.mutationProbability));
      mutationProbabilityFormattedTextField.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
         public void propertyChange(java.beans.PropertyChangeEvent evt) {
            mutationProbabilityFormattedTextFieldPropertyChange(evt);
         }
      });
      gridBagConstraints = new java.awt.GridBagConstraints();
      gridBagConstraints.gridx = 1;
      add(mutationProbabilityFormattedTextField, gridBagConstraints);

      jLabel2.setText("maximum size of probability combination vectors: ");
      gridBagConstraints = new java.awt.GridBagConstraints();
      gridBagConstraints.gridx = 0;
      gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
      add(jLabel2, gridBagConstraints);

      maxPoolSizeFormattedTextField.setColumns(5);
      maxPoolSizeFormattedTextField.setValue(new Integer (Chromosome.Parameters.maxPoolSize));
      maxPoolSizeFormattedTextField.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
         public void propertyChange(java.beans.PropertyChangeEvent evt) {
            maxPoolSizeFormattedTextFieldPropertyChange(evt);
         }
      });
      gridBagConstraints = new java.awt.GridBagConstraints();
      gridBagConstraints.gridx = 1;
      add(maxPoolSizeFormattedTextField, gridBagConstraints);

      jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("standard deviation normal distribution"));
      jPanel1.setLayout(new java.awt.GridBagLayout());

      jLabel3.setText("size of probability combination vectors: ");
      gridBagConstraints = new java.awt.GridBagConstraints();
      gridBagConstraints.gridx = 0;
      gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
      jPanel1.add(jLabel3, gridBagConstraints);

      stddevNormalPoolSizeFormattedTextField.setColumns(5);
      stddevNormalPoolSizeFormattedTextField.setValue(new Float (Chromosome.Parameters.stddevNormalPoolSize));
      stddevNormalPoolSizeFormattedTextField.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
         public void propertyChange(java.beans.PropertyChangeEvent evt) {
            stddevNormalPoolSizeFormattedTextFieldPropertyChange(evt);
         }
      });
      gridBagConstraints = new java.awt.GridBagConstraints();
      gridBagConstraints.gridx = 1;
      jPanel1.add(stddevNormalPoolSizeFormattedTextField, gridBagConstraints);

      jLabel4.setText("utility threshold: ");
      gridBagConstraints = new java.awt.GridBagConstraints();
      gridBagConstraints.gridx = 0;
      gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
      jPanel1.add(jLabel4, gridBagConstraints);

      stddevNormalUtilityThresholdFormattedTextField.setColumns(5);
      stddevNormalUtilityThresholdFormattedTextField.setValue(new Float (Chromosome.Parameters.stddevNormalUtilityThreshold));
      stddevNormalUtilityThresholdFormattedTextField.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
         public void propertyChange(java.beans.PropertyChangeEvent evt) {
            stddevNormalUtilityThresholdFormattedTextFieldPropertyChange(evt);
         }
      });
      gridBagConstraints = new java.awt.GridBagConstraints();
      gridBagConstraints.gridx = 1;
      jPanel1.add(stddevNormalUtilityThresholdFormattedTextField, gridBagConstraints);

      jLabel5.setText("probability update factor: ");
      gridBagConstraints = new java.awt.GridBagConstraints();
      gridBagConstraints.gridx = 0;
      gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
      jPanel1.add(jLabel5, gridBagConstraints);

      stddevNormalDeltaFormattedTextField.setColumns(5);
      stddevNormalDeltaFormattedTextField.setValue(new Float (Chromosome.Parameters.stddevNormalDelta));
      stddevNormalDeltaFormattedTextField.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
         public void propertyChange(java.beans.PropertyChangeEvent evt) {
            stddevNormalDeltaFormattedTextFieldPropertyChange(evt);
         }
      });
      gridBagConstraints = new java.awt.GridBagConstraints();
      gridBagConstraints.gridx = 1;
      jPanel1.add(stddevNormalDeltaFormattedTextField, gridBagConstraints);

      jLabel6.setText("bits per probability: ");
      gridBagConstraints = new java.awt.GridBagConstraints();
      gridBagConstraints.gridx = 0;
      gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
      jPanel1.add(jLabel6, gridBagConstraints);

      stddevBitsPerProbabilityFormattedTextField.setColumns(5);
      stddevBitsPerProbabilityFormattedTextField.setValue(new Float (Chromosome.Parameters.stddevBitsPerProbability));
      stddevBitsPerProbabilityFormattedTextField.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
         public void propertyChange(java.beans.PropertyChangeEvent evt) {
            stddevBitsPerProbabilityFormattedTextFieldPropertyChange(evt);
         }
      });
      gridBagConstraints = new java.awt.GridBagConstraints();
      gridBagConstraints.gridx = 1;
      jPanel1.add(stddevBitsPerProbabilityFormattedTextField, gridBagConstraints);

      gridBagConstraints = new java.awt.GridBagConstraints();
      gridBagConstraints.gridx = 0;
      gridBagConstraints.gridwidth = 2;
      gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
      add(jPanel1, gridBagConstraints);
   }// </editor-fold>//GEN-END:initComponents

	 private void defaultGenesCheckBoxActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_defaultGenesCheckBoxActionPerformed
		Chromosome.Parameters.defaultGenes = this.defaultGenesCheckBox.isSelected ();
		this.firePropertyChange ("chromosome", null, null);
	 }//GEN-LAST:event_defaultGenesCheckBoxActionPerformed

	 private void mutationProbabilityFormattedTextFieldPropertyChange (java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_mutationProbabilityFormattedTextFieldPropertyChange
		if (evt.getPropertyName ().equals ("value")) {
			final float value = (Float) this.mutationProbabilityFormattedTextField.getValue ();
			final boolean ok = value >= 0 && value <= 1;
			if (ok) {
				Chromosome.Parameters.mutationProbability = value;
				this.firePropertyChange ("chromosome", null, null);
			}
			Util.update (this.mutationProbabilityFormattedTextField, ok);
		}
	 }//GEN-LAST:event_mutationProbabilityFormattedTextFieldPropertyChange

	 private void maxPoolSizeFormattedTextFieldPropertyChange (java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_maxPoolSizeFormattedTextFieldPropertyChange
		if (evt.getPropertyName ().equals ("value")) {
			final int value = (Integer) this.maxPoolSizeFormattedTextField.getValue ();
			final boolean ok = value >= 0;
			if (ok) {
				Chromosome.Parameters.maxPoolSize = value;
				this.firePropertyChange ("chromosome", null, null);
			}
			Util.update (this.maxPoolSizeFormattedTextField, ok);
		}
	 }//GEN-LAST:event_maxPoolSizeFormattedTextFieldPropertyChange

	 private void stddevNormalPoolSizeFormattedTextFieldPropertyChange (java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_stddevNormalPoolSizeFormattedTextFieldPropertyChange
		if (evt.getPropertyName ().equals ("value")) {
			final float value = (Float) this.stddevNormalPoolSizeFormattedTextField.getValue ();
			final boolean ok = value >= 0;
			if (ok) {
				Chromosome.Parameters.stddevNormalPoolSize = value;
				this.firePropertyChange ("chromosome", null, null);
			}
			Util.update (this.stddevNormalPoolSizeFormattedTextField, ok);
		}
	 }//GEN-LAST:event_stddevNormalPoolSizeFormattedTextFieldPropertyChange

	 private void stddevNormalUtilityThresholdFormattedTextFieldPropertyChange (java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_stddevNormalUtilityThresholdFormattedTextFieldPropertyChange
		if (evt.getPropertyName ().equals ("value")) {
			final float value = (Float) this.stddevNormalUtilityThresholdFormattedTextField.getValue ();
			final boolean ok = value >= 0;
			if (ok) {
				Chromosome.Parameters.stddevNormalUtilityThreshold = value;
				this.firePropertyChange ("chromosome", null, null);
			}
			Util.update (this.stddevNormalUtilityThresholdFormattedTextField, ok);
		}
	 }//GEN-LAST:event_stddevNormalUtilityThresholdFormattedTextFieldPropertyChange

	 private void stddevNormalDeltaFormattedTextFieldPropertyChange (java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_stddevNormalDeltaFormattedTextFieldPropertyChange
		if (evt.getPropertyName ().equals ("value")) {
			final float value = (Float) this.stddevNormalDeltaFormattedTextField.getValue ();
			final boolean ok = value >= 0;
			if (ok) {
				Chromosome.Parameters.stddevNormalDelta = value;
				this.firePropertyChange ("chromosome", null, null);
			}
			Util.update (this.stddevNormalDeltaFormattedTextField, ok);
		}
	 }//GEN-LAST:event_stddevNormalDeltaFormattedTextFieldPropertyChange

	 private void stddevBitsPerProbabilityFormattedTextFieldPropertyChange (java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_stddevBitsPerProbabilityFormattedTextFieldPropertyChange
		if (evt.getPropertyName ().equals ("value")) {
			final float value = (Float) this.stddevBitsPerProbabilityFormattedTextField.getValue ();
			final boolean ok = value >= 0;
			if (ok) {
				Chromosome.Parameters.stddevBitsPerProbability = value;
				this.firePropertyChange ("chromosome", null, null);
			}
			Util.update (this.stddevBitsPerProbabilityFormattedTextField, ok);
		}
	 }//GEN-LAST:event_stddevBitsPerProbabilityFormattedTextFieldPropertyChange


   // Variables declaration - do not modify//GEN-BEGIN:variables
   private javax.swing.JCheckBox defaultGenesCheckBox;
   private javax.swing.JFormattedTextField maxPoolSizeFormattedTextField;
   private javax.swing.JFormattedTextField mutationProbabilityFormattedTextField;
   private javax.swing.JFormattedTextField stddevBitsPerProbabilityFormattedTextField;
   private javax.swing.JFormattedTextField stddevNormalDeltaFormattedTextField;
   private javax.swing.JFormattedTextField stddevNormalPoolSizeFormattedTextField;
   private javax.swing.JFormattedTextField stddevNormalUtilityThresholdFormattedTextField;
   // End of variables declaration//GEN-END:variables

}

// Local Variables:
// mode: java
// mode: flyspell-prog
// ispell-local-dictionary: "british"
// End:
